home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8048 < prev    next >
Encoding:
Text File  |  1996-08-05  |  997 b   |  51 lines

  1. Path: newsbf02.news.aol.com!not-for-mail
  2. From: tycope@aol.com (Tycope)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Simple Loop answer
  5. Date: 1 Mar 1996 03:49:51 -0500
  6. Organization: America Online, Inc. (1-800-827-6364)
  7. Sender: root@newsbf02.news.aol.com
  8. Message-ID: <4h6dnf$fts@newsbf02.news.aol.com>
  9. Reply-To: tycope@aol.com (Tycope)
  10. NNTP-Posting-Host: newsbf02.mail.aol.com
  11.  
  12. Here is what I finally came up with.........
  13.  
  14.  
  15. #include <stdio.h>
  16. #define MAX 1000
  17.  
  18. long int i, j, k, l;
  19. long int count = 0;
  20. long int compares = 0;
  21.  
  22. int
  23. main (void)
  24. {
  25.  
  26.  
  27.     for     (i = 1; i <= MAX - 3; i++)
  28.     for    (j = i + 1; j <= MAX - 2; j++)
  29.     for    (k = j + 1; k <= MAX - 1; k++)
  30.     {
  31.         l = i + j + k;
  32.         compares++;
  33.     
  34.     if (((0 < i) && (i < j)) && ((j < k)  && (k < l)))
  35.     if (l <= MAX)
  36.        {    count++;
  37.     if (compares % 1000000 == 0)
  38.         {
  39.             printf("%ld(i) + %ld(j) + %ld(k) = %ld(l)\n", i,
  40. j, k, l);
  41.  
  42.        }
  43.         }
  44.     }
  45.  
  46.     printf("The number of triples is: %ld\n\n", count);
  47.     printf("The number of compares is: %ld\n", compares);
  48.  
  49.     return (0);
  50. }
  51.